﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace carsitem.kucun
{
    public partial class kucun : Form
    {
        DataTable dt = new DataTable();//在内存创建了一个表对象
        public static string conn = "Data Source=季白\\MSSQLSERVER04;Initial Catalog=SellCars;Integrated Security=True";

        public kucun()
        {
            InitializeComponent();
            
        }

        private void kucun_FormClosed(object sender, FormClosedEventArgs e)
        {
            Application.Exit();
        }

        private void kucun_Load(object sender, EventArgs e)
        {

            //// TODO: 这行代码将数据加载到表“kucunshuju.Warehouse”中。您可以根据需要移动或删除它。
            //this.warehouseTableAdapter.Fill(this.kucunshuju.Warehouse);

            //1.创建数据库连接对象
            SqlConnection con = new SqlConnection(conn);
            //con.open();
            //2.创建命令对象
            string sql = "select Kucun.*,WarehouseName from kucun join Warehouse on kucun.WarehouseID = Warehouse.WarehouseID";
            //SqlCommand com = new SqlCommand(sql, con);
            //3.执行select查询命令，获取DateAdapter对象
            SqlDataAdapter dap = new SqlDataAdapter(sql, con);
            //填充DataSet
            //DataSet ds = new DataSet();//内存临时仓库
            //dap.Fill(ds);//默认填充在ds的第一张表
            DataTable dt = new DataTable();//在内存创建了一个表对象
            dap.Fill(dt);
            //设置不自动生成列
            //this.kucunbiao.AutoGenerateColumns = false;
            //设置Datagridview控件的数据源
            // this.Song_dgv.DataSource = ds.Tables[0];//获取ds的第一张表
            this.kucunbiao.DataSource = dt;
        }

        private void Exit_btn_Click(object sender, EventArgs e)
        {
            //Application.Exit();
            carsitem.MainInterface.MainInterfaceForm mainInterfaceForm = new carsitem.MainInterface.MainInterfaceForm();//把form1传给form2
            mainInterfaceForm.Show();
            this.Hide();//把自己隐藏了
        }
        
    }
}
